package com.lanou.horo.zhuizhui.utility.factory;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.SparseArray;

import com.lanou.horo.zhuizhui.fragment.CommunityPageEssenceFragment;

/**
 * Created by dllo on 15/10/20.
 */
public class FragmentFactory {

    private static SparseArray<Fragment> fragmentMap = new SparseArray<>();

    public static Fragment createFragment(int position) {

        Fragment f = fragmentMap.get(position);
        if (f == null) {
            String url=null;
            switch (position) {
                case 0:
                    url = "http://api.zhuizhuiyoyo.com/request.php?method=topics%2Flist&timestamp=1446087267730&param=%7B%22count%22%3A20%2C%22page%22%3A1%2C%22tag%22%3A%22best%22%7D&sig=cfa95b836a8772847700bb29f2c98edb";
                    break;
                case 1:
                    url = "http://api.zhuizhuiyoyo.com/request.php?method=topics%2Flist&timestamp=1446087388395&param=%7B%22count%22%3A20%2C%22type%22%3A4%2C%22page%22%3A1%7D&sig=446114ff377da6f95c85e951c0072e73";
                    break;
                case 2:
                    url = "http://api.zhuizhuiyoyo.com/request.php?method=topics%2Flist&timestamp=1446087467263&param=%7B%22count%22%3A20%2C%22type%22%3A3%2C%22page%22%3A1%7D&sig=d4105f1aa0635da47ea71ac026b54406";
                    break;
                case 3:
                    url = "http://api.zhuizhuiyoyo.com/request.php?method=topics%2Flist&timestamp=1446087571879&param=%7B%22count%22%3A20%2C%22type%22%3A12%2C%22page%22%3A1%7D&sig=cdf8dd0d3c3f204b9140fb32b507f3c7";
                    break;
                case 4:
                    url = "http://api.zhuizhuiyoyo.com/request.php?method=topics%2Flist&timestamp=1446087601430&param=%7B%22count%22%3A20%2C%22type%22%3A7%2C%22page%22%3A1%7D&sig=11b5e6f31ad50d5f93b82dd35e1b6957";
                    break;
                case 5:
                    url = "http://api.zhuizhuiyoyo.com/request.php?method=topics%2Flist&timestamp=1446087630262&param=%7B%22count%22%3A20%2C%22type%22%3A1%2C%22page%22%3A1%7D&sig=373b1e4354b21ed1443e7aeeb318d0e3";
                    break;
                case 6:
                    url = "http://api.zhuizhuiyoyo.com/request.php?method=topics%2Flist&timestamp=1446087804012&param=%7B%22count%22%3A20%2C%22type%22%3A8%2C%22page%22%3A1%7D&sig=6726c5aa48b7c996b8fa5638e9adab6c";
                    break;
            }

                f = new CommunityPageEssenceFragment(url);
                Bundle args = new Bundle();
                args.putInt("position", position);
                f.setArguments(args);

            fragmentMap.put(position, f);
        }
        return f;
    }


}
